package com.luojie.controller.user;


import com.luojie.dto.MatchesDTO;
import com.luojie.dto.MatchesQueryDTO;
import com.luojie.result.Result;
import com.luojie.service.MatchesService;
import com.luojie.vo.MatchesVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController("userMatchesControll")
@RequestMapping("/roger/user/matches")
@Api(tags = "c端用户相关接口")
@Slf4j
public class MatchesController {
    @Autowired
    private MatchesService matchesService;

    @PostMapping("/seletc")
    @ApiOperation("查询发布比赛信息信息")
    public Result<MatchesVo> selectMatches(Integer id) {
        try {
            log.info("查询发布比赛:{}", id);
            MatchesVo matchesVo = matchesService.selectMatches(id);
            return Result.success(matchesVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("查询比赛失败");
    }

    @PostMapping()
    @ApiOperation("添加发布比赛")
    public Result addMatch(@RequestBody MatchesDTO matchesDTO) {
        try {
            log.info("添加发布比赛:{}", matchesDTO);
            matchesService.addMatch(matchesDTO);
            return Result.success("新增比赛成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("新增比赛失败");
    }
    @DeleteMapping
    @ApiOperation("删除比赛")
    public Result deleteMatch(Integer id) {
        try {
            log.info("删除比赛:{}", id);
            matchesService.deletById(id);
            return Result.success("删除比赛成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("删除比赛失败");
    }
    @PostMapping("/Update")
    @ApiOperation("修改比赛")
    public Result updateMatch(@RequestBody MatchesDTO matchesDTO) {
        try {
            log.info("修改比赛:{}", matchesDTO);
            matchesService.updateMatch(matchesDTO);
            return Result.success("修改比赛成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("修改比赛失败");
    }

    @PostMapping("/page")
    @ApiOperation("分页查询比赛")
    public Result<List<MatchesVo>> page(@RequestBody MatchesQueryDTO matchesDTO) {
        try {
            log.info("分页查询比赛:{}", matchesDTO);
            List<MatchesVo> matchesVos = matchesService.page(matchesDTO);
            return Result.success(matchesVos);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("分页查询比赛失败");
    }

}
